# $Id: Query.pm,v 1.1 2004/02/21 18:48:07 ibo Exp $
# This small class allows handle_submission methods to bind_param in the
# current prepared SQL statement without sharing a ref to an integer.

package CGI::FOGE2::Query;
use strict;

use DBI;

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my ($sth, $index) = @_;

    my $self = {
        sth     => $sth,
        index   => $index,
        content => [],
    };
    bless ($self, $class);
    return $self;
}

sub add_param {
    my $self = shift;
    my ($value) = @_;

    $self->{index}++;
    eval {
        $self->{sth}->bind_param($self->{index}, $value);
        push @{$self->{content}}, $value;
    };
    if ( $@ ) {
        die "Cannot bind_param for " . $self->{sth} 
    . " at index " . $self->{index} . " to store value: " . $value
    . "\nSTH is " . $self->dump();
    };
}

# Useful for debug

sub dump {
    my $self = shift;
    print STDERR "[" . ref($self) 
        . " index=" . $self->{index}
        . " content=(" . join(', ', @{$self->{content}})
        . "]";
}

1;

# end of Query.pm
    
